<template>
	<view>
		<view class="flex around">
			<view style="width: 200rpx;padding: 100rpx 0;">
				<image src="/static/logo.png" mode="widthFix" class="image"></image>
			</view>
		</view>

		<view class="flex default-window" style="justify-content: space-around">
			<view style="width: 400rpx;">
				<button @click="wxLogin()" class="login-btn">
					微信登录
				</button>
			</view>
			

		</view>
		
		<view @click="quxiao" class="default-window u-text-center">
			取消登录
		</view>
		<view style="display: flex;justify-content: center;">
			请详细阅读<navigator style="color: blue;" url="/pages/usercenter/privacyPolicy/privacyPolicy">《隐私政策》</navigator>与<navigator
				url="/pages/usercenter/userAgreement/userAgreement" style="color: blue;">《用户手册》</navigator>
		</view>
		
		<agree :isBack="true"/>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			};
		},
		computed: {
			ref_sn() {
				return this.$store.state.login.ref_sn
			},

		},
		methods: {
			quxiao() {
				uni.navigateBack({

				})
			},
			//微信登录
			wxLogin(e) {
				this.$showLoading()
				let that = this;
				let code = '';
				wx.login({
					provider: 'weixin',
					success: function(loginRes) {
						code = loginRes.code;
						console.log(code);

					},
					fail: function(res) {
						that.$showHide()
					}
				});
				wx.getUserProfile({
					desc: "将获取您的登录信息",
					success(res) {
						let params = {
							nickname: res.userInfo.nickName,
							headimgurl: res.userInfo.avatarUrl,
							code: code,
							sn: that.ref_sn,
							type: 1,
							rawData: res.rawData,
							iv: res.iv,
							encryptedData: res.encryptedData
						}
						that.$api('login/mini_login', params).then(data => {
							if (data.status == 1) {
								uni.setStorageSync('token', data.data.token);
								uni.setStorageSync('sn', data.data.sn);
								uni.setStorageSync('shopName', data.data.shop_name);
								uni.setStorageSync('shopId', data.data.shop_id);
								that.$store.commit('setLoginAction', {
									loginAction: true,
									_this: that,
								});

								uni.navigateBack({

								})
								that.$showHide();
							} else if (data.status == 2) {
								uni.redirectTo({
									url: '/pages/public/bind1'
								})
							} else {
								that.$showToast(data.msg);
							}

						})
					},
					fail() {
						that.$showHide()
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}

	.login-btn {
		background: linear-gradient(to left, #19be6b 0, #18b566 100%);
		color: #FFFFFF;
		border-radius: 60rpx;
		width: 400rpx;
		margin-top: 40rpx;
	}
</style>
